/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 74646
 * Date: 2022-02-20
 * Time: 12:34
 */
class Person{
    private String name;
    private int age;
}

class MyArrayList<E>{
    private E[] array; //保存Object类型的顺序表元素
    private int usedSize; //顺序表有效数据个数
    public MyArrayList(){
        this.array = (E[]) new Object[10];
    }
    //插入元素
    public void add(E val){
        this.array[usedSize] = val;
        usedSize++;
    }
    //获取pos位置的元素
    public E get(int pos){
        return this.array[pos];
    }
}

public class TestDemo2 {
    public static void main(String[] args) {
        //myArrayList1 引用的类型： MyArrayList<String>
        MyArrayList<String> myArrayList1 = new MyArrayList<>();
        MyArrayList<Integer> myArrayList2 = new MyArrayList<>();
        //打印内容：类型@地址值
        System.out.println(myArrayList1);
        System.out.println(myArrayList2);
    }

    public static void main3(String[] args) {
        MyArrayList<String> myArrayList = new MyArrayList<>();
        myArrayList.add("ABC");
        myArrayList.add("DEF");
        String ret = myArrayList.get(1);
        System.out.println(ret);
    }

    public static void main2(String[] args) {
        MyArrayList<Person> myArrayList1 =new MyArrayList();
        myArrayList1.add(new Person());
        MyArrayList<Integer> myArrayList2 = new MyArrayList();
        myArrayList2.add(1);
        MyArrayList<String> myArrayList3 = new MyArrayList();
        myArrayList3.add("abc");
    }

    public static void main1(String[] args) {
        MyArrayList myArrayList1 =new MyArrayList();
        myArrayList1.add(new Person());
        MyArrayList myArrayList2 = new MyArrayList();
        myArrayList2.add(1);
        myArrayList2.add("abc");
        //myArrayList2 引用指向的数组，下标为1的元素是字符串
        //但是myArrayList2 引用指向的数组的返回值是Object类型，所以要强制类型转换
        String ret =(String) myArrayList2.get(1);
    }
}
